﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharePointUtilitiesForDevelopers.Action;
using SharePointUtilitiesForDevelopers.Actions.Forms;
using System.Windows.Forms;

namespace SharePointUtilitiesForDevelopers.Actions
{
  class ManageEventReceiversAction : IAction
  {

    #region IAction Members

    /// <summary>
    /// Gets the title
    /// </summary>
    public string Title
    {
      get { return Properties.Resources.ManageEventReceiversTitle; }
    }

    public string Description
    {
      get { return Properties.Resources.ManageEventReceiversDescription; }
    }

    public ActionTarget Target
    {
      get { return ActionTarget.List; }
    }

    public void Execute(ActionContext actionContext)
    {

      string listName = null;
      string webUrl = null;
      

      if (actionContext.Entity is SharePointList)
      {
        var list = (SharePointList)actionContext.Entity;

        webUrl = actionContext.Web.Url;
        listName = list.Id;

      }

      if (webUrl!= null && listName!=null)
      {
        var form = ServiceLocator.Resolve<EventReceiversForm>();
        form.WebUrl = webUrl;
        form.ListGUID = listName;
        form.LoadReceivers();
        form.ShowDialog(actionContext.Owner as IWin32Window);
      }
    }

    #endregion
  }
}
